package com.sinsoft.monitorDemo.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sinsoft.monitorDemo.dao.ThresholdDao;
import com.sinsoft.monitorDemo.entity.Threshold;

@Controller
@RequestMapping("/Threshold")
public class ThresholdController {
	
	@RequestMapping("/getAllThreshold")
	public String getAllThreshold(HttpServletRequest request){
		ThresholdDao thresholdDao = new ThresholdDao();
		Threshold threshold = thresholdDao.getAllThreshold();
		HttpSession session = request.getSession();
		session.setAttribute("threshold", threshold);
		return "index";
	}
	
	@RequestMapping("/ChangeThreshold")
	public String ChangeThreshold(Threshold threshold){
		ThresholdDao thresholdDao = new ThresholdDao();
		if (threshold.getCpuUsed()!=null) {
			thresholdDao.changeThreshold("cpuUsed", threshold.getCpuUsed().toString());			
		}
		if (threshold.getMemUsed()!=null) {
			thresholdDao.changeThreshold("memUsed", threshold.getMemUsed().toString());		
		}
		if (threshold.getSwapUsed()!=null) {
			thresholdDao.changeThreshold("swapUsed", threshold.getSwapUsed().toString());	
		}
		if (threshold.getDiskUsed()!=null) {
			thresholdDao.changeThreshold("diskUsed", threshold.getDiskUsed().toString());
		}
		if (threshold.getCpuIowait()!=null) {
			thresholdDao.changeThreshold("cpuIowait", threshold.getCpuIowait().toString());
		}
		if (threshold.getTomcatCpuUsed()!=null) {
			thresholdDao.changeThreshold("tomcatCpuUsed", threshold.getTomcatCpuUsed().toString());
		}
		if (threshold.getTomcatMemUsed()!=null) {
			thresholdDao.changeThreshold("tomcatMemUsed", threshold.getTomcatMemUsed().toString());
		}
		if (threshold.getNginxCpuUsed()!=null) {
			thresholdDao.changeThreshold("nginxCpuUsed", threshold.getNginxCpuUsed().toString());
		}
		if (threshold.getNginxMemUsed()!=null) {
			thresholdDao.changeThreshold("nginxMemUsed", threshold.getNginxMemUsed().toString());
		}
		if (threshold.getMysqlCpuUsed()!=null) {
			thresholdDao.changeThreshold("mysqlCpuUsed", threshold.getMysqlCpuUsed().toString());
		}
		if (threshold.getMysqlMemUsed()!=null) {
			thresholdDao.changeThreshold("mysqlMemUsed", threshold.getMysqlMemUsed().toString());
		}
		if (threshold.getOracleTmpfsUsed()!=null) {
			thresholdDao.changeThreshold("oracleTmpfsUsed", threshold.getOracleTmpfsUsed().toString());
		}
		if (threshold.getOracletablespaceused()!=null) {
			thresholdDao.changeThreshold("oracletablespaceused", threshold.getOracletablespaceused().toString());
		}
		return "index";
	}

}
